package com.sxhalo.fsms.service.impl;

import java.util.List;

import com.sxhalo.fsms.domain.RedisData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sxhalo.fsms.domain.MotorReliabilityData;
import com.sxhalo.fsms.mapper.MotorReliabilityDataMapper;
import com.sxhalo.fsms.service.IMotorReliabilityDataService;

@Service
public class MotorReliabilityDataServiceImpl implements IMotorReliabilityDataService {

	@Autowired
	private MotorReliabilityDataMapper mapper;
	
	@Override
	public Integer insertSelective(MotorReliabilityData record) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer updateByPrimaryKeySelective(MotorReliabilityData record) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer deleteByPrimaryKey(Object key) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public MotorReliabilityData selectByPrimaryKey(Object key) {
		return mapper.selectByPrimaryKey(Integer.parseInt(key.toString()));
	}

	@Override
	public List<MotorReliabilityData> findWhereList(String where, String order) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer getCount(String where) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MotorReliabilityData> findPagerList(Integer start, Integer length, String where, String order) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer saveOrUpdate(List<MotorReliabilityData> list) {
		for (int i = 0; i < list.size(); i++) {

			MotorReliabilityData old = mapper.selectByPrimaryKey(list.get(i).getDeviceId());
			if (old == null) {
				mapper.insertSelective(list.get(i));
			} else {
				//有变化才更新
				if (!old.equals(list.get(0))) {
					mapper.updateByPrimaryKeySelective(list.get(i));
				}
			}

		}
		return 0;
	}


	@Override
	public Integer saveOrUpdateRedisData(List<RedisData> list) {
	if(list.size()>0){
		return   mapper.saveOrUpdateRedisData(list);
	}
		return 0;
	}



}
